import { Router } from 'express';
import { UserController } from '../controllers/user-controller';
import { DepartmentController } from '../controllers/department-controller';
import { dictionaryController } from '../controllers/dictionary-controller';
import { authMiddleware } from '../middleware/auth'; // 导入auth中间件

const router: Router = Router();

// 用户管理
router.get('/user/list', authMiddleware, UserController.getUsers);
router.post('/user', authMiddleware, UserController.createUser);
router.get('/user/:id', authMiddleware, UserController.getUserById);
router.put('/user', authMiddleware, UserController.updateUser);
router.delete('/user/:id', authMiddleware, UserController.deleteUser);
router.post(
  '/user/reset-password/:id',
  authMiddleware,
  UserController.resetPassword
);
router.post('/user/change-password', authMiddleware, UserController.changePassword);

// 部门管理
router.get(
  '/department/list',
  authMiddleware,
  DepartmentController.getDepartments
);
router.get(
  '/department/tree',
  authMiddleware,
  DepartmentController.getDepartmentTree
);
router.post(
  '/department',
  authMiddleware,
  DepartmentController.createDepartment
);
router.get(
  '/department/:id',
  authMiddleware,
  DepartmentController.getDepartmentById
);
router.put(
  '/department',
  authMiddleware,
  DepartmentController.updateDepartment
);
router.delete(
  '/department/:id',
  authMiddleware,
  DepartmentController.deleteDepartment
);

// 字典管理
router.get(
  '/dictionary/list',
  authMiddleware,
  dictionaryController.getDictionaries.bind(dictionaryController)
);
router.post(
  '/dictionary',
  authMiddleware,
  dictionaryController.createDictionary.bind(dictionaryController)
);
router.get(
  '/dictionary/:id',
  authMiddleware,
  dictionaryController.getDictionaryById.bind(dictionaryController)
);
router.get(
  '/dictionary/code/:code',
  authMiddleware,
  dictionaryController.getDictionaryByCode.bind(dictionaryController)
);
router.put(
  '/dictionary/:id',
  authMiddleware,
  dictionaryController.updateDictionary.bind(dictionaryController)
);
router.delete(
  '/dictionary/:id',
  authMiddleware,
  dictionaryController.deleteDictionary.bind(dictionaryController)
);
router.put(
  '/dictionary/batch/sort',
  authMiddleware,
  dictionaryController.batchUpdateDictionariesSort.bind(dictionaryController)
);

// 字典项
router.get(
  '/dictionary-item/list',
  authMiddleware,
  dictionaryController.getDictionaryItems.bind(dictionaryController)
);
router.post(
  '/dictionary-item',
  authMiddleware,
  dictionaryController.createDictionaryItem.bind(dictionaryController)
);
router.get(
  '/dictionary-item/:id',
  authMiddleware,
  dictionaryController.getDictionaryItemById.bind(dictionaryController)
);
router.get(
  '/dictionary-item/code/:code',
  authMiddleware,
  dictionaryController.getDictionaryItemsByCode.bind(dictionaryController)
);
router.put(
  '/dictionary-item/:id',
  authMiddleware,
  dictionaryController.updateDictionaryItem.bind(dictionaryController)
);
router.delete(
  '/dictionary-item/:id',
  authMiddleware,
  dictionaryController.deleteDictionaryItem.bind(dictionaryController)
);
router.put(
  '/dictionary-item/batch/sort',
  authMiddleware,
  dictionaryController.batchUpdateDictionaryItemsSort.bind(dictionaryController)
);

export default router;
